<?php

if(!defined('IN_UCHOME')) {
	exit('Access Denied');
}
$view = empty($_GET['view'])?'myship':trim($_GET['view']);

if($view == 'getflist'){

	//分页
	$perpage = 5;
	$perpage = mob_perpage($perpage);

	$friendlist = array();
	$count = 0;
	$page = empty($_GET['page'])?0:intval($_GET['page']);
	if($page<1) $page = 1;
	$start = ($page-1)*$perpage;

	//处理查询
	$theurl = "space.php?do=findship_page&view=getflist&ajaxdiv=friend_list&inajax=1";

	if($space['friendnum']) {
		$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM (SELECT ship.uid from ".tname('friend')." main
					RIGHT JOIN ".tname('ship_att')." ship ON ship.uid=main.fuid
					WHERE main.uid='$space[uid]' AND main.status='1' GROUP BY ship.uid ) tlist"), 0);
		if($count) {
			$query = $_SGLOBAL['db']->query("SELECT s.uid, s.username, s.name, s.namestatus, main.num, ship.Id as shipid
				FROM ".tname('friend')." main
				LEFT JOIN ".tname('space')." s ON s.uid=main.fuid
				RIGHT JOIN ".tname('ship_att')." ship ON ship.uid=main.fuid
				WHERE main.uid='$space[uid]' AND main.status='1' GROUP BY s.username
				ORDER BY main.num DESC, main.dateline DESC
				LIMIT $start,$perpage");
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				realname_set($value['uid'], $value['username'], $value['name'], $value['namestatus']);
				$friendlist[$value['uid']] = $value;
			}
		}

		//分页
		$multi = multi($count, $perpage, $page, $theurl, 'friend_list');
	}

	realname_get();
	include_once template("space_findship");

}elseif($view == 'getmtaglist'){

	//分页
	$perpage = 5;
	$perpage = mob_perpage($perpage);

	$friendlist = array();
	$count = 0;
	$page = empty($_GET['page'])?0:intval($_GET['page']);
	if($page<1) $page = 1;
	$start = ($page-1)*$perpage;

	//处理查询
	$theurl = "space.php?do=findship_page&view=getmtaglist&ajaxdiv=mtag_list&inajax=1";

	$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM (SELECT ship.uid from ".tname('tagspace')." main
				RIGHT JOIN ".tname('ship_att')." ship ON ship.uid=main.uid
				WHERE main.tagid='$space[com_id]' AND main.uid != '$_SGLOBAL[supe_uid]' GROUP BY ship.uid ) tlist"), 0);
	if($count) {
		$query = $_SGLOBAL['db']->query("SELECT s.uid, s.username, s.name, s.namestatus, ship.Id as shipid
			FROM ".tname('tagspace')." main
			LEFT JOIN ".tname('space')." s ON s.uid=main.uid
			RIGHT JOIN ".tname('ship_att')." ship ON ship.uid=main.uid
			WHERE main.tagid='$space[com_id]' AND main.uid != '$_SGLOBAL[supe_uid]'
			GROUP BY s.uid ORDER BY s.uid DESC LIMIT $start,$perpage");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			realname_set($value['uid'], $value['username'], $value['name'], $value['namestatus']);
			$mtaglist[$value['uid']] = $value;
		}
	}

	//分页
	$multi = multi($count, $perpage, $page, $theurl, 'mtag_list');


	realname_get();
	include_once template("space_findship");

}elseif(intval($_GET['pid']) || $_SGLOBAL['supe_uid']){

	//引航计划表查询
	$p_uid = intval($_GET['id']);
	$f_uid = intval($_GET['fuid']);
	if(empty($p_uid)){
		$p_uid = $_SGLOBAL['supe_uid'];
	}
	$query = $_SGLOBAL['db']->query("SELECT username FROM ".tname('member')." WHERE uid=".$p_uid);
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		$username = $value['username'];
	}

	$trends_a = array('FAR_BERTH'=>'离泊','NEAR_BERTH'=>'靠泊','MOVE_BERTH'=>'移泊');
	$status_a = array('CANCEL'=>'取消','NO_CONFIRMED'=>'申报','CONFIRMED'=>'确报','AUDITED'=>'已审核','REJECTED'=>'驳回','ASSIGNED'=>'已排班','FINISHED'=>'已完成','HIS'=>'历史记录','BALANCE'=>'结算','REJECT_HIS'=>'驳回历史记录');

	//分页
	$pperpage = 10;
	$pperpage = mob_perpage($pperpage);

	$planlist = array();
	$pcount = 0;
	$start = intval($_GET['start']);
	if($start < 0) $start = 0;

	$wheresql = " userid='".$username."'";
	$ts = '';
	if(!empty($_GET['trends'])){
		$wheresql.=" AND trends='".$_GET['trends']."'";
		$ts .= "&trends=".$_GET['trends'];
		$trends = $_GET['trends'];
	}
	if(!empty($_GET['status'])){
		$wheresql.=" AND status='".$_GET['status']."'";
		$ts .= "&status=".$_GET['status'];
		$status = $_GET['status'];
	}

	//处理查询
	$thepurl = "space.php?do=findship_page&id=".$p_uid.$ts."&ajaxdiv=shipplan&inajax=1";

	$query = $_SGLOBAL['db']->query("SELECT shipcallsign, plantime, shipname, shipename,nationality, trends, origin, stop, status, pilot, pilot2, agency, dispatcher
		FROM ".tname('plan')." WHERE ".$wheresql." ORDER BY plantime desc
		LIMIT $start,$pperpage");
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		$value['trends'] = $trends_a[$value['trends']];
		$value['status'] = $status_a[$value['status']];
		$planlist[] = $value;
		$pcount++;
	}

	//分页
	$pmulti = smulti($start, $pperpage, $pcount, $thepurl, 'shipplan');

	$view = 'planlist';

	include_once template("space_findship");

}

?>